<?php
	include_once('../inc/config.php');

    $route = 'nuevo_multiple';

	if( $_SESSION['multiple']==0 ){
		die('No tiene permisos para administrar más de un alojamiento');
	}
	
    $parent_id = $_SESSION['login'];
	$id        = 0;	

	
    if($_POST['submit']){

        $data = $_POST;

		unset($data['submit']);
		
		$sql = "select * from productos where id='{$data['parent_id']}' ";
		$rs  = $db->SelectLimit($sql,1);
        $z   = $rs->FetchRow();
		$data['email'] = $z['email'];

		$data['fecha'] = time();
		
        $db->debug = false;
        $ok = $db->Replace('productos', $data,'id', $autoquote = true); 

		
		$sql = "select id from productos where parent_id='{$data['parent_id']}' order by id DESC";
		$rs  = $db->SelectLimit($sql,1);
        $z   = $rs->FetchRow();
		$nueva_id = $z['id'];
		
        redirect(URL."/account/mi_cuenta.php?id=$nueva_id");
        die();



    } else {
        $cond   = "select * from productos where id='{$_SESSION['login']}'";
        $rs     = $db->SelectLimit($cond, 1);
        $data   = $rs->FetchRow();
		$data['parent_id'] = $_SESSION['login'];

        // -ARMA LOS SELECT DE LAS FAMILIAS
        $Familias = crearArbol(0);
        $parent_id = 0;
        $select_familia = '<select name="familia_id" class="required">';
        foreach($Familias as $dd){
                if ($data['familia_id'] == $dd['id']) { $sel = "selected='selected'"; } else {$sel='';}
                $separador = "";
                if ($dd['nivel'] == 2 ) {
                    $separador = "------";
                } elseif ($dd['nivel'] == 3 ) {
                    $separador = "------------";
                } elseif ($dd['nivel'] == 4 ) {
                    $separador = "------------------";
                }
                $select_familia.= "<option value='{$dd['id']}' $sel >$separador {$dd['nombre1']}</option>";
        }
        $select_familia.= "</select>";

       
    }

    include_once(ROOT.'/html/header_resumido.html.php');
    include_once(ROOT.'/account/nuevo_alojamiento.html.php');
  //  include_once(ROOT.'/html/footer.html.php');

?>